package org.example.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.example.entity.Meeting;
import org.example.entity.MeetingQueryDTO;
import org.example.service.MeetingService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/meeting")
public class MeetingController {
    @Resource
    private MeetingService meetingService;

    /**
     * 分页查询会议列表
     */
    @GetMapping("/list")  // 新增分页查询接口
    public ResponseEntity<IPage<Meeting>> getMeetingList(MeetingQueryDTO query) {
        return ResponseEntity.ok(meetingService.getMeetingList(query));
    }

    /**
     * 获取会议详情
     */
    @GetMapping("/detail/{id}")
    public ResponseEntity<Meeting> getMeetingDetail(@PathVariable Integer id) {  // 统一为Integer类型
        return ResponseEntity.ok(meetingService.getMeetingDetail(id));
    }

    /**
     * 导出会议数据
     */
    @GetMapping("/export")
    public void exportMeetingList(MeetingQueryDTO query, HttpServletResponse response) throws IOException {
        List<Meeting> meetingList = meetingService.exportMeetingList(query);

        // 设置响应头，处理文件下载
        response.setContentType("application/vnd.ms-excel");
        response.setHeader("Content-Disposition", "attachment;filename=meeting_list.xlsx");

        // 实际项目中使用POI等工具类生成Excel文件
        // ExcelUtil.exportMeetingList(response.getOutputStream(), meetingList);
    }
}